home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / bob13.arc / BOB.C next >
Text File  |  1991-10-01  |  2KB  |  97 lines

  1. /* bob.c - the main routine */
  2. /*
  3.     Copyright (c) 1991, by David Michael Betz
  4.     All rights reserved
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <setjmp.h>
  9. #include "bob.h"
  10.  
  11. /* Revision history
  12.  
  13.     1.0    08/15/91    Initial version for DDJ article
  14.     1.1    08/20/91    Fixed do_for to allow null statements
  15.     1.2    08/28/91    Fixed problem with newobject()
  16.     1.3    09/27/91    Fixed a bug in compact_vector()
  17. */
  18.  
  19. #define BANNER    "Bob v1.3 - Copyright (c) 1991, by David Betz"
  20.  
  21. /* global variables */
  22. jmp_buf error_trap;
  23. char **bobargv;
  24. int bobargc;
  25.  
  26. /* external variables */
  27. extern int decode,trace;
  28.  
  29. /* main - the main routine */
  30. main(argc,argv)
  31.   int argc; char *argv[];
  32. {
  33.     char fullname[20];
  34.     int i;
  35.  
  36.     /* display the banner */
  37.     osputs(BANNER);
  38.     osputs("\n");
  39.  
  40.     /* initialize */
  41.     initialize(SMAX,CMAX);
  42.     bobargc = argc - 1;
  43.     bobargv = argv + 1;
  44.  
  45.     /* load and execute some code */
  46.     for (i = 1; i < argc; ++i)
  47.     if (strcmp(argv[i],"-d") == 0)
  48.         decode = 1;
  49.     else if (strcmp(argv[i],"-t") == 0)
  50.         trace = 1;
  51.     else {
  52.         strcpy(fullname,argv[i]);
  53.         strcat(fullname,".bob");
  54.         compile_file(fullname);
  55.     }
  56.     if (!execute("main"))
  57.     printf("Can't execute 'main'\n");
  58. }
  59.  
  60. /* compile_file - compile definitions in a file */
  61. static compile_file(name)
  62.   char *name;
  63. {
  64.     FILE *ifp;
  65.     if ((ifp = fopen(name,"r")) != NULL) {
  66.     compile_definitions(fgetc,ifp);
  67.     fclose(ifp);
  68.     }
  69. }
  70.  
  71. /* info - display progress information */
  72. info(fmt,a1,a2,a3,a4,a5,a6)
  73.   char *fmt;
  74. {
  75.     char buf1[100],buf2[100];
  76.     sprintf(buf1,fmt,a1,a2,a3,a4,a5,a6);
  77.     sprintf(buf2,"[ %s ]\n",buf1);
  78.     osputs(buf2);
  79. }
  80.  
  81. /* error - print an error message and exit */
  82. error(fmt,a1,a2,a3,a4)
  83.   char *fmt;
  84. {
  85.     char buf1[100],buf2[100];
  86.     sprintf(buf1,fmt,a1,a2,a3,a4);
  87.     sprintf(buf2,"Error: %s\n",buf1);
  88.     osputs(buf2);
  89.     longjmp(error_trap,1);
  90. }
  91.  
  92. osputs(str)
  93.   char *str;
  94. {
  95.     fputs(str,stderr);
  96. }
  97.